/*
 * @Descripttion: 
 * @version: 
 * @Author: 马琳峰
 * @Date: 2020-11-13 13:54:30
 * @LastEditors: 马琳峰
 * @LastEditTime: 2020-11-13 15:04:40
 */
const path = require('path');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

const webpack = require('webpack');

module.exports = {
  entry: './src/main.js',
  output: {
    filename: '[name].js?[hash]', // 添加哈希值，防止缓存
    path: path.resolve(__dirname, 'dist'), // 输出文件夹
  },
  module: {
    rules: [
      {
        test: /.css$/,
        use: [
          'style-loader',
          'css-loader',
        ],
      },
      {
        test: /.less$/,
        use: ['style-loader', 'css-loader', 'less-loader'],
      },
      {
        test: /.vue$/,
        use: 'vue-loader',
      },
      {
        test: /\.(png|jpg|gif|jpeg)$/,
        use: [{
          loader: 'url-loader',
          options: {
            esModule: false,
            limit: 10 * 1024,
            outputPath: 'img',
            name: '[name].[hash:8].[ext]',
          },
        }],
      },
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/, // 排除这两个文件夹
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env'],
          },
        },
      },
      {
        test: /\.(js|vue)$/,
        exclude: /node_modules/,
        loader: 'eslint-loader',
        include: [path.resolve(__dirname, 'src')], // 指定检查的目录
        options: {},
      },
    ],
  },
  plugins: [
    new CleanWebpackPlugin(),
    new VueLoaderPlugin(),
    new webpack.DefinePlugin({
      BASE_URL: '"./"',
    }),
    new HtmlWebpackPlugin({
      template: './public/index.html',
    }),
  ],
};
